package com.ckm.controller;

import com.ckm.annotation.LogInfo;
import com.ckm.entity.Course;
import com.ckm.entity.ResponseResult;
import com.ckm.service.CourseService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@LogInfo
@Validated
@RestController
@RequestMapping("course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 添加课程
     * @param collegeList 课程信息list
     * @return 成功信息
     */
    @PostMapping("addCourse")
    public ResponseResult addCourse(@RequestBody @Valid List<Course> collegeList) {
        courseService.addCourse(collegeList);
        return new ResponseResult(200,"添加成功",null);
    }

    /**
     * 更新课程
     * @param course 更新的信息
     * @return 成功信息
     */
    @PutMapping
    public ResponseResult updateCourse(@RequestBody Course course) {
        courseService.updateCourse(course);
        return new ResponseResult(200,"更新成功","");
    }

    /**
     * 删除课程
     * @param id 课程Id
     * @return 成功信息
     */
    @DeleteMapping
    public ResponseResult deleteCourse(@RequestParam(name = "id") Integer id) {
        courseService.deleteCourse(id);
        return new ResponseResult(200,"删除成功","");
    }

    /**
     * 查找课程信息
     * @param course 查找词
     * @param pageNum 页码
     * @param pageSize 页大小
     * @return 分页结果集
     */
    @PostMapping("find")
    public ResponseResult findCourse(@RequestBody Course course, @RequestParam(name = "pageNum",defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", defaultValue = "10") int pageSize) {
        return new ResponseResult(200,"查找完毕",courseService.getCoursePage(course,pageNum,pageSize));
    }
}
